<!-- 修改密码 -->
<template>
  <div class="change-password">
    <van-nav-bar
      title="修改密码"
      @click-left="() => $router.go(-1)"
      left-arrow
      safe-area-inset-top
    >
    </van-nav-bar>

    <div class="form">
      <van-form ref="form">
        <van-field
          center
          v-model="form.password"
          :type="type1"
          name="密码"
          placeholder="请输入原密码"
          :rules="[{ required: true, message: '请输入密码' }]"
        >
          <template #left-icon>
            <div class="icon">
              <img src="../../assets/images/user/密码.png" alt="" />
            </div>
          </template>
          <template #right-icon>
            <van-icon
              v-if="type1 == 'password'"
              name="closed-eye"
              @click="click1(1)"
            />
            <van-icon v-else name="eye-o" @click="click1(1)" />
          </template>
        </van-field>
        <van-field
          center
          v-model="form.password1"
          :type="type2"
          name="密码"
          placeholder="请输入新密码"
          :rules="[{ required: true, message: '请输入新密码' }]"
        >
          <template #left-icon>
            <div class="icon">
              <img src="../../assets/images/user/密码.png" alt="" />
            </div>
          </template>
          <template #right-icon>
            <van-icon
              v-if="type2 == 'password'"
              name="closed-eye"
              @click="click1(2)"
            />
            <van-icon v-else name="eye-o" @click="click1(2)" />
          </template>
        </van-field>
        <van-field
          center
          v-model="form.password2"
          :type="type3"
          name="密码"
          placeholder="请输入确认密码"
          :rules="[{ required: true, message: '请输入确认密码' }]"
        >
          <template #left-icon>
            <div class="icon">
              <img src="../../assets/images/user/密码.png" alt="" />
            </div>
          </template>
          <template #right-icon>
            <van-icon
              v-if="type3 == 'password'"
              name="closed-eye"
              @click="click1(3)"
            />
            <van-icon v-else name="eye-o" @click="click1(3)" />
          </template>
        </van-field>
      </van-form>
    </div>

    <div class="bottom">
      <van-button
        round
        block
        type="info"
        @click="onSubmit"
        color="linear-gradient(to right, rgb(120, 184, 246), rgb(29,97,214))"
        style="font-size: 20px"
        >确认修改</van-button
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      form: {
        password: "",
        password1: "",
        password2: "",
      },
      type1: "password",
      type2: "password",
      type3: "password",
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", this.$refs.form);
      this.$refs.form
        .validate()
        .then((res) => {
          // 表单验证通过
          console.log(res);
        })
        .catch((err) => {
          // 表单验证不通过
          console.log("cuole", err);
        });
    },
    click1(val) {
      this["type" + val] == "password"
        ? (this["type" + val] = "text")
        : (this["type" + val] = "password");
    },
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
};
</script>

<style lang="scss" scoped>
.change-password {
  width: 100%;
  height: 100vh;
  background-color: #fff;
  position: relative;
  .form {
    width: 90%;
    border: 1px solid #eee;
    margin: 50px auto;
    box-shadow: 0 0 10px rgb(223, 237, 248);
    border-radius: 15px;
    .icon {
      width: 100px;
      text-align: center;
      border-right: 1px solid #daf2fd;
      margin-right: 20px;
      img {
        width: 50px;
        height: 50px;
      }
    }
  }
  .bottom {
    margin: 16px;
    width: 90%;
    height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: absolute;
    bottom: 5%;
    left: 2.5%;
  }
}
</style>